package com.jcdd.utils;

import com.jcdd.constant.YjyStore;
import com.qiniu.common.QiniuException;
import com.qiniu.storage.DownloadUrl;
import com.qiniu.util.Auth;

public class Qiniu {
    public static String getImageUrl(String key){
        String domain = YjyStore.imgsDomain;
        //图片key
        DownloadUrl url = new DownloadUrl(domain, true, key);
        // url.setAttname(attname) // 配置 attname
        //         .setFop(fop) // 配置 fop
        //         .setStyle(style, styleSeparator, styleParam) // 配置 style
        // 带有效期
        long expireInSeconds = 32000000;//32000000s大约一年多一点点
        long deadline = System.currentTimeMillis()/1000 + expireInSeconds;
        Auth auth = Auth.create(YjyStore.qiniuAccessKey, YjyStore.qiniuSecretKey);
        String urlString = null;
        try {
            urlString = url.buildURL(auth, deadline);
        } catch (QiniuException e) {
            throw new RuntimeException(e);
        }
        return urlString;
    }
}
